const express = require('express');
const app  = express();
const cors = require('cors');
const port = 5279;
const userRouter = require('./router/userRouter.js');
const activityRouter = require('./router/activityRouter.js');
const carRouter = require('./router/carRouter.js');
const informationRouter = require('./router/informationRouter.js');
const swiperRouter = require('./router/swiperRouter.js');
const collectRouter = require('./router/collectRouter.js');
const orderRouter = require('./router/orderRouter.js');
//使用cors来处理跨域问题
app.use(cors());
//处理JSON格式的请求体
app.use(express.json());
//处理URL编码的请求体
app.use(express.urlencoded({extended:true}));
//express托管静态资源
app.use("/img/",express.static('img/'));
//注册路由模块
app.use('/api/user',userRouter);
app.use('/api/activity',activityRouter);
app.use('/api/car',carRouter);
app.use('/api/information',informationRouter);
app.use('/api/swiper',swiperRouter);
app.use('/api/collect',collectRouter);
app.use('/api/order',orderRouter);
app.use('/api/test',(req,res)=>{
    res.send("测试接口访问成功！");
})
//监听5279端口
app.listen(port,()=>{
    console.log(`
    rent-car-server已启动......
    listen into:http://localhost:${port}/`);
})